﻿using Fluffy.Library.DocumentContainer;
using Fluffy.Library.FileSources;
using System;
using System.IO;
using System.Linq;

namespace Fluffy.Text
{
	public class TextDocument : IDocumentContainer
    {
		private readonly string[] _supportedExtensions =
		{
			".txt",
			".ini",
			".cs",
			".js",
			".htm",
			".html",
			".asp",
			".aspx",
			".asax",
			".asmx",
			".ascx",
			".master",
			".boo",
			".atg",
			".css",
			".c",
			".h",
			".cc",
			".cpp",
			".hpp",
			".java",
			".patch",
			".diff",
			".ps1",
			".psm1",
			".psd1",
			".php",
			".tex",
			".vb",
			".md",
			".xml",
			".xsl",
			".xslt",
			".xsd",
			".manifest",
			".config",
			".addin",
			".xshd",
			".wxs",
			".wxi",
			".wxl",
			".proj",
			".csproj",
			".vbproj",
			".ilproj",
			".booproj",
			".build",
			".xfrm",
			".targets",
			".xaml",
			".xpt",
			".xft",
			".map",
			".wsdl",
			".disco",
			".ps1xml",
			".nuspec"
		};
		
		public string Title
		{
			get { return "Text"; }
		}

		public DocumentViewModelBase GenerateViewModel(IFile file)
		{
			TextDocumentModel document = new TextDocumentModel(file);
			TextDocumentViewModel viewModel = new TextDocumentViewModel(document);

			return viewModel;
		}

		public bool IsFileExtensionSupported(IFile file)
		{
			string extension = Path.GetExtension(file.FileName);
			return _supportedExtensions.Any(x => x.Equals(extension, StringComparison.InvariantCultureIgnoreCase));
		}
    }
}
